﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_WA_UpdatePositionDutyTime]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_WA_UpdatePositionDutyTime];
GO
CREATE PROCEDURE [dbo].[sproc_WA_UpdatePositionDutyTime]
    @PositionID  int,
    @ondutytime  datetime,
    @offdutytime datetime
AS
BEGIN
SET NOCOUNT ON

UPDATE dbo.UDS_WorkAttendence_DutyTime SET OnDutyTime = @OnDutyTime, OffDutyTime = @OffDutyTime WHERE [ID] = @PositionID AND IDType = N'Position';

IF ( @@ROWCOUNT = 0 )
BEGIN
    INSERT INTO dbo.UDS_WorkAttendence_DutyTime ([ID], IDType, OnDutyTime, OffDutyTime) VALUES(@PositionID, N'Position', @ondutytime, @offdutytime);
END

RETURN @@error

END
GO